from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-18 14:04:25.118231
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 18, Aug, 2022
Time: 14:04:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1465
Nobs: 752.000 HQIC: -50.4866
Log likelihood: 9549.74 FPE: 9.58007e-23
AIC: -50.6998 Det(Omega_mle): 8.50618e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294947 0.055181 5.345 0.000
L1.Burgenland 0.108054 0.036652 2.948 0.003
L1.Kärnten -0.106749 0.019438 -5.492 0.000
L1.Niederösterreich 0.208110 0.076460 2.722 0.006
L1.Oberösterreich 0.110052 0.074476 1.478 0.139
L1.Salzburg 0.253938 0.039177 6.482 0.000
L1.Steiermark 0.038610 0.051092 0.756 0.450
L1.Tirol 0.107052 0.041409 2.585 0.010
L1.Vorarlberg -0.060376 0.035552 -1.698 0.089
L1.Wien 0.051127 0.066078 0.774 0.439
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061682 0.115027 0.536 0.592
L1.Burgenland -0.033573 0.076402 -0.439 0.660
L1.Kärnten 0.047118 0.040518 1.163 0.245
L1.Niederösterreich -0.174878 0.159384 -1.097 0.273
L1.Oberösterreich 0.403112 0.155247 2.597 0.009
L1.Salzburg 0.288006 0.081667 3.527 0.000
L1.Steiermark 0.107122 0.106503 1.006 0.315
L1.Tirol 0.312747 0.086319 3.623 0.000
L1.Vorarlberg 0.025988 0.074109 0.351 0.726
L1.Wien -0.029545 0.137742 -0.214 0.830
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189421 0.028378 6.675 0.000
L1.Burgenland 0.089774 0.018849 4.763 0.000
L1.Kärnten -0.008716 0.009996 -0.872 0.383
L1.Niederösterreich 0.260928 0.039321 6.636 0.000
L1.Oberösterreich 0.135878 0.038301 3.548 0.000
L1.Salzburg 0.045426 0.020148 2.255 0.024
L1.Steiermark 0.018524 0.026275 0.705 0.481
L1.Tirol 0.092968 0.021295 4.366 0.000
L1.Vorarlberg 0.058526 0.018283 3.201 0.001
L1.Wien 0.118506 0.033982 3.487 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106838 0.028876 3.700 0.000
L1.Burgenland 0.046444 0.019180 2.421 0.015
L1.Kärnten -0.014325 0.010172 -1.408 0.159
L1.Niederösterreich 0.192733 0.040011 4.817 0.000
L1.Oberösterreich 0.292928 0.038973 7.516 0.000
L1.Salzburg 0.110957 0.020501 5.412 0.000
L1.Steiermark 0.102691 0.026736 3.841 0.000
L1.Tirol 0.108561 0.021669 5.010 0.000
L1.Vorarlberg 0.069816 0.018604 3.753 0.000
L1.Wien -0.017408 0.034578 -0.503 0.615
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127762 0.052367 2.440 0.015
L1.Burgenland -0.050646 0.034782 -1.456 0.145
L1.Kärnten -0.040564 0.018446 -2.199 0.028
L1.Niederösterreich 0.171090 0.072560 2.358 0.018
L1.Oberösterreich 0.140636 0.070677 1.990 0.047
L1.Salzburg 0.288329 0.037179 7.755 0.000
L1.Steiermark 0.034101 0.048486 0.703 0.482
L1.Tirol 0.162106 0.039297 4.125 0.000
L1.Vorarlberg 0.100752 0.033739 2.986 0.003
L1.Wien 0.068483 0.062708 1.092 0.275
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055454 0.041767 1.328 0.184
L1.Burgenland 0.040585 0.027742 1.463 0.143
L1.Kärnten 0.050418 0.014712 3.427 0.001
L1.Niederösterreich 0.221363 0.057873 3.825 0.000
L1.Oberösterreich 0.286689 0.056371 5.086 0.000
L1.Salzburg 0.044680 0.029654 1.507 0.132
L1.Steiermark -0.000769 0.038672 -0.020 0.984
L1.Tirol 0.146693 0.031343 4.680 0.000
L1.Vorarlberg 0.072532 0.026909 2.695 0.007
L1.Wien 0.083188 0.050015 1.663 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.176875 0.049905 3.544 0.000
L1.Burgenland -0.003934 0.033147 -0.119 0.906
L1.Kärnten -0.061950 0.017579 -3.524 0.000
L1.Niederösterreich -0.080743 0.069150 -1.168 0.243
L1.Oberösterreich 0.196203 0.067355 2.913 0.004
L1.Salzburg 0.056647 0.035432 1.599 0.110
L1.Steiermark 0.232558 0.046207 5.033 0.000
L1.Tirol 0.494966 0.037450 13.217 0.000
L1.Vorarlberg 0.046792 0.032153 1.455 0.146
L1.Wien -0.055069 0.059760 -0.921 0.357
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164453 0.057486 2.861 0.004
L1.Burgenland -0.010649 0.038183 -0.279 0.780
L1.Kärnten 0.067233 0.020250 3.320 0.001
L1.Niederösterreich 0.206637 0.079654 2.594 0.009
L1.Oberösterreich -0.068065 0.077587 -0.877 0.380
L1.Salzburg 0.210283 0.040814 5.152 0.000
L1.Steiermark 0.117158 0.053226 2.201 0.028
L1.Tirol 0.070407 0.043139 1.632 0.103
L1.Vorarlberg 0.121715 0.037037 3.286 0.001
L1.Wien 0.122495 0.068838 1.779 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359206 0.032996 10.886 0.000
L1.Burgenland 0.007053 0.021916 0.322 0.748
L1.Kärnten -0.023542 0.011623 -2.026 0.043
L1.Niederösterreich 0.214873 0.045719 4.700 0.000
L1.Oberösterreich 0.197046 0.044533 4.425 0.000
L1.Salzburg 0.044409 0.023426 1.896 0.058
L1.Steiermark -0.014898 0.030551 -0.488 0.626
L1.Tirol 0.104600 0.024761 4.224 0.000
L1.Vorarlberg 0.072560 0.021258 3.413 0.001
L1.Wien 0.040638 0.039511 1.029 0.304
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039508 0.143964 0.192595 0.153873 0.121912 0.107608 0.064773 0.219926
Kärnten 0.039508 1.000000 -0.005875 0.132963 0.039632 0.095084 0.431217 -0.053291 0.097994
Niederösterreich 0.143964 -0.005875 1.000000 0.336867 0.144349 0.297312 0.100664 0.181380 0.316671
Oberösterreich 0.192595 0.132963 0.336867 1.000000 0.226960 0.330284 0.172313 0.166733 0.263327
Salzburg 0.153873 0.039632 0.144349 0.226960 1.000000 0.145031 0.116825 0.145747 0.126036
Steiermark 0.121912 0.095084 0.297312 0.330284 0.145031 1.000000 0.148278 0.136626 0.075755
Tirol 0.107608 0.431217 0.100664 0.172313 0.116825 0.148278 1.000000 0.113180 0.145839
Vorarlberg 0.064773 -0.053291 0.181380 0.166733 0.145747 0.136626 0.113180 1.000000 0.003145
Wien 0.219926 0.097994 0.316671 0.263327 0.126036 0.075755 0.145839 0.003145 1.000000